let _this = '';
const thisVm = (vue) => {
	_this = vue;
}
const cellphone = [{
	validator: (rule, value, callback) => {
		let reg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
		if ($.trim(value) == '') {
			callback(new Error('请输入手机号码'));
		} else if (!reg.test(value)) {
			callback(new Error('请输入有效手机号码'));
		} else {
			callback();
		}
	},
	trigger: 'blur'
}];
const telephone = [{
	validator: (rule, value, callback) => {
		let reg = /(^(\d{3})-(\d{8})$)|(^(\d{4})-(\d{7})$)/;
		if ($.trim(value) == '') {
			callback(new Error('请输入电话号码'));
		} else if (!reg.test(value)) {
			callback(new Error('请输入有效电话号码'));
		} else {
			callback();
		}
	},
	trigger: 'blur'
}];
const phoneORphone = [{
	validator: (rule, value, callback) => {
		let reg1 = /^[1][3,4,5,7,8][0-9]{9}$/;
		let reg2 = /(^(\d{3})-(\d{8})$)|(^(\d{4})-(\d{7})$)/;
		if ($.trim(value) == '') {
			callback(new Error('请输入联系方式'));
		} else if (!reg1.test(value) && !reg2.test(value)) {
			callback(new Error('请输入有效号码'));
		} else {
			callback();
		}
	},
	trigger: 'blur'
}];
const password = [{
	validator: (rule, value, callback) => {
		let reg = /^[a-zA-Z0-9]{6,18}$/;
		if ($.trim(value) == '') {
			callback(new Error('请输入密码'));
		} else if (!reg.test(value)) {
			callback(new Error('请输入6-18位密码'));
		} else {
			callback();
		}
	},
	trigger: 'blur'
}];
const ImgCode = [{
	validator: (rule, value, callback) => {
		let reg = /^[a-zA-Z0-9]{4}$/;
		if ($.trim(value) == '') {
			callback(new Error('请输入图形验证码'));
		} else if (!reg.test(value)) {
			callback(new Error('请输入图形验证码'));
		} else {
			callback();
		}
	},
	trigger: 'blur'
}];
const SmsCode = [{
	validator: (rule, value, callback) => {
		let reg = /^\d{4}$/;
		if ($.trim(value) == '') {
			callback(new Error('请输入手机验证码'));
		} else if (!reg.test(value)) {
			callback(new Error('请输入有效手机验证码'));
		} else {
			callback();
		}
	},
	trigger: 'blur'
}];
const Email = [{
	validator: (rule, value, callback) => {
		let reg =
			/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
		if ($.trim(value) == '') {
			callback(new Error('请输入Email地址'));
		} else if (!reg.test(value)) {
			callback(new Error('请输入有效Email地址'));
		} else {
			callback();
		}
	},
	trigger: 'blur'
}];
const IP = [{
	validator: (rule, value, callback) => {
		let reg =
			/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
		if ($.trim(value) == '') {
			callback(new Error('请输入IP地址'));
		} else if (!reg.test(value)) {
			callback(new Error('请输入有效IP地址'));
		} else {
			callback();
		}
	},
	trigger: 'blur'
}];
const URL = [{
	validator: (rule, value, callback) => {
		let reg = /^(((ht|f)tps?):\/\/)?[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?$/;
		if ($.trim(value) == '') {
			callback(new Error('请输入URL地址'));
		} else if (!reg.test(value)) {
			callback(new Error('请输入有效URL地址'));
		} else {
			callback();
		}
	},
	trigger: 'blur'
}];
const NotNull = [{
	validator: (rule, value, callback) => {
		if ($.trim(value) == '') {
			callback(new Error('请输入'));
		} else {
			callback();
		}
	},
	trigger: 'blur'
}];
const number = [{
	validator: (rule, value, callback) => {
		let reg = /^\d{1,}$/;
		if ($.trim(value) == '') {
			callback(new Error('请输入数字'));
		} else if (!reg.test(value)) {
			callback(new Error('请输入数字'));
		} else {
			callback();
		}
	},
	trigger: 'blur'
}];
const temperature = [{
	validator: (rule, value, callback) => {
		let reg = /^[0-9]+(.[0-9]{1})?$/;
		if ($.trim(value) == '') {
			callback(new Error('请输入正数字或一位小数'));
		} else if (!reg.test(value)) {
			callback(new Error('请输入正数字或最多两位小数'));
		} else {
			callback();
		}
	},
	trigger: 'blur'
}];
const money = [{
	validator: (rule, value, callback) => {
		let reg = /^[0-9]+(.[0-9]{1,2})?$/;
		if ($.trim(value) == '') {
			callback(new Error('请输入金额'));
		} else if (!reg.test(value)) {
			callback(new Error('请输入正数字或最多两位小数'));
		} else {
			callback();
		}
	},
	trigger: 'change'
}];
const CouponMoney = [{
	validator: (rule, value, callback) => {
		let reg = /^[1-9]\d*$/;
		if ($.trim(value) == '') {
			callback(new Error('请输入金额'));
		} else if (!reg.test(value)) {
			callback(new Error('请输入正数字'));
		} else {
			callback();
		}
	},
	trigger: 'change'
}];
const discount = [{
	validator: (rule, value, callback) => {
		let reg = /^[0-9]+(.[0-9]{1})?$/;
		if ($.trim(value) == '') {
			callback(new Error('请输入折扣'));
		} else if (!reg.test(value) || value == 0 || value >= 10) {
			callback(new Error('请输入一位正整数或最多一位小数'));
		} else {
			callback();
		}
	},
	trigger: 'change'
}];
const Select = [{
	validator: (rule, value, callback) => {
		if ($.trim(value) == '') {
			callback(new Error('请选择'));
		} else {
			callback();
		}
	},
	trigger: 'change'
}];
const Power = [{
	validator: (rule, value, callback) => {
		if ($.trim(value) == '') {
			callback(new Error('请选择权限'));
		} else {
			callback();
		}
	},
	trigger: 'change'
}];
const fileImg = [{
	validator: (rule, value, callback) => {
		if ($.trim(value) == '@/assets/img/fileImg-bj.png') {
			callback(new Error('请上传'));
		} else {
			callback();
		}
	},
	trigger: 'change'
}];
const array = [{
	validator: (rule, value, callback) => {
		if (value.length == 0) {
			callback(new Error('请选择'));
		} else {
			callback();
		}
	},
	trigger: 'change'
}];

export default {
	thisVm,
	cellphone, //手机号
	telephone, //电话号
	phoneORphone, //手机号or电话号
	password, //密码
	ImgCode, //图形验证码
	SmsCode, //手机-短信验证码
	Email, //邮箱
	IP, //IP
	URL, //URL地址
	NotNull, //非空
	number, //数字
	temperature, //温度
	Select, //Select选择
	Power, //权限
	fileImg, //上传文件
	array, //非空数组
	money, //金额
	CouponMoney, //优惠券金额
	discount //折扣
}
